package com.tjl.yangxixis.activity;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

import com.blankj.utilcode.util.ToastUtils;
import com.lyp.adapters.ResetAdapter;
import com.lyp.jsonbean.LoginBean;
import com.lyp.jsonbean.RenYuanBean;
import com.tjl.yangxixis.R;
import com.tjl.yangxixis.api.YangxixiApi;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 *
 * @author Administrator
 *  销售经理的重置密码界面
 */
public class ResetPwdActivity extends Activity implements OnClickListener{

	private ImageView mback;
	private RecyclerView mRecyclerView;
	private LinearLayoutManager mLinearLayoutManager;
	private ResetAdapter mAdapter;//个人信息
	private List<RenYuanBean.DataBean> mList = new ArrayList<>();
	private LoginBean.DataBean bean;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_reset_pwd);
		initview();
	}

	public void initview(){
		bean = (LoginBean.DataBean) getIntent().getExtras().get("databean");
		mback = (ImageView) findViewById(R.id.iv_reset_back);
		mRecyclerView = (RecyclerView) findViewById(R.id.resets_recycler);
		mLinearLayoutManager = new LinearLayoutManager(this);
		mRecyclerView.setLayoutManager(mLinearLayoutManager);
		mAdapter = new ResetAdapter(mList,this);
		mRecyclerView.setAdapter(mAdapter);
		mback.setOnClickListener(this);

		try {
			renyuan(bean.getC_id());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}


	//全部人员
	public void renyuan(String c_id) throws IOException {
		Retrofit retrofit = new Retrofit.Builder()
				.baseUrl(YangxixiApi.APP_URL)
				.addConverterFactory(GsonConverterFactory.create())
				.build();
		YangxixiApi github = retrofit.create(YangxixiApi.class);
		Call<RenYuanBean> call = github.getRenyuan(c_id);
		call.enqueue(new Callback<RenYuanBean>() {
			@Override
			public void onResponse(Call<RenYuanBean> call, final Response<RenYuanBean> response) {
				if (response.body().getResult()== 1 ) {
					ResetPwdActivity.this.runOnUiThread(new Runnable() {
						@Override
						public void run() {
							mList.addAll(response.body().getData());
							mAdapter.notifyDataSetChanged();
						}
					});
				}else {
					ToastUtils.showShort(response.body().getMessage());
				}
			}
			@Override
			public void onFailure(Call<RenYuanBean> call, Throwable t) {
				ToastUtils.showShort(t.getMessage());
			}
		});
	}


	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		switch (arg0.getId()) {
			case R.id.iv_reset_back:
				finish();
				break;
		}

	}
}
